libxl: clear O_NONBLOCK|O_NDELAY on migration fd and reinstate afterwards
authorIan Campbell <ian.campbell@citrix.com>
Fri, 11 Sep 2015 10:42:51 +0000 (11:42 +0100)
committerIan Campbell <ian.campbell@citrix.com>
Fri, 11 Sep 2015 13:42:40 +0000 (14:42 +0100)
commit93f5194e72708776783f2d34894c9b42031e116e
tree4a78b5565d39f41466999d72f9b47f35ab04dd3f
parent88ab6b65395b2c81ede747cf2d13814241111ee6
libxl: clear O_NONBLOCK|O_NDELAY on migration fd and reinstate afterwards

The fd passed to us by libvirt for both save and restore has at least
O_NONBLOCK set, which libxl does not expect and therefore fails to
handle any EAGAIN which might arise.

This has been observed with migration v2, but if v1 used to work I
think that would be just be by luck and/or coincidence.

Unix convention (and the principal of least surprise) is usually to
ensure that an fd has no "strange" properties, such as being
non-blocking, when handing it to another component.

However for the convenience of the application arrange instead for
libxl to clear any unexpected flags on the file descriptors it is
given for save or restore and restore them to their original state at
the end. O_NDELAY could be similarly problematic so clear that as
well as O_NONBLOCK.

To do this introduce a pair of new helper functions one to modify+save
the flags and another to restore them and call them in the appropriate
places.

The migration v1 code appeared to do some things with O_NONBLOCK in
the checkpoint case. Migration v2 doesn't seem to do so, and in any
case I wouldn't expect it to be relying on libvirt's setting of
O_NONBLOCK when xl doesn't use that flag.

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
Acked-by: Wei Liu <wei.liu2@citrix.com>
Cc: Jim Fehlig <jfehlig@suse.com>
Cc: Andrew Cooper <andrew.cooper3@citrix.com>
Cc: Shriram Rajagopalan <rshriram@cs.ubc.ca>
Cc: Yang Hongyang <yanghy@cn.fujitsu.com>
tools/libxl/libxl.c
tools/libxl/libxl_create.c
tools/libxl/libxl_internal.h